package com.szd.qiongyou20.home.search.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.szd.qiongyou20.R;
import com.szd.qiongyou20.home.search.bean.GoodsBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by SZD on 2016/12/26.
 */

public class Goods_ListView_Adapter extends BaseAdapter {

    private Context mContext;
    private List<GoodsBean.DataBean.ListBean> mList;

    public Goods_ListView_Adapter(Context context, List<GoodsBean.DataBean.ListBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_search_sp, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // 获取数据
        String photo = mList.get(position).getPhoto();
        String title = mList.get(position).getTitle();
        String mark = mList.get(position).getMark();
        String sold = mList.get(position).getSold();
        String price = mList.get(position).getPrice();

        // 将数据添加到View中
        Glide.with(mContext).load(photo).into(holder.mImageViewSearchSpShow);
        holder.mTextViewSearchSpDetail.setText(title);
        holder.mTextViewSearchSpCount.setText(sold);
        holder.mTextViewSearchSpPrice.setText(price);
        if (mark.equals(""))
            holder.mTextViewSearchSpMdd.setVisibility(View.INVISIBLE);
        holder.mTextViewSearchSpMdd.setText(mark);

        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.imageView_search_sp_show)
        ImageView mImageViewSearchSpShow;
        @Bind(R.id.textView_search_privilege)
        TextView mTextViewSearchPrivilege;
        @Bind(R.id.textView_search_sp_detail)
        TextView mTextViewSearchSpDetail;
        @Bind(R.id.textView_search_sp_mdd)
        TextView mTextViewSearchSpMdd;
        @Bind(R.id.textView_search_sp_count)
        TextView mTextViewSearchSpCount;
        @Bind(R.id.textView_search_sp_price)
        TextView mTextViewSearchSpPrice;
        @Bind(R.id.textView_yuanqi)
        TextView mTextViewYuanqi;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
